package ar.edu.unlu.sistemas.p2p.android;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import ar.edu.unlu.sistemas.p2p.business.util.Constants;
import ar.edu.unlu.sistemas.p2p.business.util.Params;

public class MainActivity extends AbsP2PActivity implements OnClickListener{
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        EditText edt = (EditText) findViewById(R.id.edit_txt_port);
        edt.setText(String.valueOf(Params.TCP_LISTEN_PORT));
        edt = (EditText) findViewById(R.id.edit_txt_alias);
        edt.setText(String.valueOf(Params.PEER_ALIAS));
        Button btn = (Button)findViewById(R.id.button_connect);
        btn.setOnClickListener(this);
    }
    
    public void onClick(View v) {
    	switch (v.getId()) {
    	case R.id.button_connect:
    		EditText edt = (EditText) findViewById(R.id.edit_txt_port);
    		int port = Integer.parseInt(edt.getText().toString());
    		edt = (EditText) findViewById(R.id.edit_txt_alias);
    		String alias = edt.getText().toString();
    		Intent serviceIntent = new Intent(MainActivity.this,AppService.class);
    		serviceIntent.putExtra(Constants.PORT, port);
    		serviceIntent.putExtra(Constants.ALIAS, alias);
    		startService(serviceIntent);
    		try {
    			Thread.sleep(500);
    		} catch (Exception e) {

    		}
    		//startActivity(new Intent(MainActivity.this,QueryActivity.class));
    		this.finish();
    		break;
    	default:
    		break;
    	}
    }
    
}